package puppy.eval;

import java.io.IOException;
import java.util.HashSet;

import puppy.graph.AgeAggregator;
import algorithms.PageRankSuggestions;
import algorithms.models.QueryTagsModel;

import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterException;

public class RunQuerySuggestionsRWLauncher {

	// model parameters
	
	private static boolean m_kids=true;
	private static boolean m_kids_teens=true;
	private static boolean m_kids_teens_mteens=false;
	private static boolean m_teens=false;
	private static boolean m_teens_mteens=false;
	private static boolean m_mteens=false;
	private static boolean m_adults=false;
	
	
	static String path = "../data/graph/last/delcious_graph_merged_enriched_inline_kids.txt";
	
	static String node_node = "../data/graph/last/tags_dmoz_bigram_subset_merged_groups_kids.txt";
	
	static String query_tags = "../data/query_tags/query_and_tags_sorted_aol.txt";
	
	static float epsilon=0.001f;
	static double alpha=0.2f;
	static int max_iterations=10;
	int n_gram_weight=2;
	int mimimum_length_ngram= 2;
	
	//gold set parameters
	
	
	//static String evaluation_path = "../data/gold_set/aol_query_reformulations/kids_long_click.txt";
	//static String evaluation_path = "../data/gold_set/aol_query_reformulations/sample.txt";
	static String evaluation_path="../data/gold_set/ydir_query_reformulations/with_long_click.txt";
	static String log_type="aol";
	static HashSet<String> valid_ages= new HashSet<String>();
	
	
	static boolean onlyClicks=false;
	static int duration =30;
	static boolean onlyManual=false;
	private static int limit=110;
	
	public static void initParameters(CommanLineParametersRW jct){
		
		if(jct.getIterations()!=0)
			max_iterations=jct.getIterations();
		
		
		if(jct.getAlpha()!=null){
			
			alpha=jct.getAlphaDouble();
		}
		
		if(jct.getEvaluation()!=null)
			evaluation_path=jct.getEvaluation();
		
		if(jct.getQuerytags()!=null)
			query_tags=jct.getQuerytags();
		
		if(jct.getLogtype()!=null)
			log_type=jct.getLogtype();
		
		
		if(jct.getNode()!=null)
			node_node=jct.getLogtype();
		
	
		if(jct.getGraph()!=null)
			path=jct.getGraph();
		
		
		if(jct.getDuration()!=0)
			duration=jct.getDuration();
		
		if(jct.getDuration()!=0)
			duration=jct.getDuration();
		
		
		
		
		if(jct.getAges()!=null){
			String ages[] = jct.getAges().split(",");
			
			for(int i =0; i <ages.length; i++){
				
				valid_ages.add(ages[i].trim());
			}
		
		}else{
			
			valid_ages.add("kids");
		//	valid_ages.add("kids-teens");
			//valid_ages.add("kids-teens-mteens");
		}
		
		
		
		
	}
	
	public static void main(String argv[]) throws IOException {
		
		
		// argv = new { "-log", "2", "-groups", "unit", "a", "b", "c" };
		CommanLineParametersRW jct = new CommanLineParametersRW();
		    JCommander cmd = new JCommander(jct);
		
		 try {
		        cmd.parse(argv);
		        //
		     
		        //
		    } catch (ParameterException ex) {
		        System.out.println(ex.getMessage());
		        cmd.usage();
		    }
		
		initParameters(jct);
	
		
		RunSuggestions runner = 
				new RunSuggestions(evaluation_path,log_type, valid_ages,onlyClicks,duration, onlyManual);
		
		//System.out.println("evaluation module loaded");
		AgeAggregator	agg= new AgeAggregator(valid_ages);
		//PageRankSuggestions page = new PageRankSuggestions(path,node_node,agg,alpha,max_iterations); //ranker
		PageRankSuggestions page = new PageRankSuggestions(path,node_node,agg,alpha,max_iterations); //ranker
			
		//System.out.println("ranking module loaded");
		QueryTagsModel querytags = new QueryTagsModel(query_tags, runner.getGoldStandard());
		
		//load bank of queries and their tags
		
		runner.rankQueries(page,querytags,limit);
		
		
	}
}
